package com.yanqu.road.server.cmd.activity.twins;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TwinsProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.twins.CrossTwinsMgr;
import com.yanqu.road.server.manager.activity.twins.activity.CrossTwinsActivity;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.math.BigInteger;

@Cmd(code = CrossProtocol.C2_CROSS_TWINS_PVP_UPDATE_USER, desc = "")
public class CrossTwinsPvpUpdateUserCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        TwinsProto.CrossTwinsPvpUpdateUserDataReqMsg reqMsg = TwinsProto.CrossTwinsPvpUpdateUserDataReqMsg.parseFrom(packet.getBytes());
        CrossTwinsActivity activity = CrossTwinsMgr.getActivity(reqMsg.getActivityId(),groupId);
        if(activity != null){
            for(TwinsProto.CrossTwinsPvpUpdateUserMsg userMsg : reqMsg.getUserList()){
                if(userMsg.getPlayerBaseData() != null){
                    UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(userMsg.getPlayerBaseData());
                    CrossUserMgr.updateUserBaseInfoChange(userMsg.getUserId(),userBaseInfo);
                }
                //todo-xx 上线了去掉
                activity.removeDebug(packet.getPlayerId());


                activity.initUserData(packet.getPlayerId(),new BigInteger(userMsg.getBool()),new BigInteger(userMsg.getAttack()));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
